{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5b592e3b-d5a2-4566-ae2d-b19f36d7665e",
   "metadata": {},
   "source": [
    "### Testing Input Boxes\n",
    "\n",
    "We need to test the `gonbui` defined in the git repository being tested.\n",
    "For that we expect `GONB_GIT_ROOT` to be set."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "05af505d-428c-4dd6-80ac-7ae467d5bc6b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "%goflags=[\"--cover\" \"--covermode=set\"]\n",
      "GOCOVERDIR=/tmp/gonb_test_coverage.6X8w4Qlxik\n"
     ]
    }
   ],
   "source": [
    "%goflags --cover --covermode=set\n",
    "import \"os\"\n",
    "\n",
    "%%\n",
    "fmt.Printf(\"GOCOVERDIR=%s\\n\", os.Getenv(\"GOCOVERDIR\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "382ac8a9-1bd0-4854-91df-5ef8fd14ea3a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ok\n"
     ]
    }
   ],
   "source": [
    "!if [[ \"${GONB_GIT_ROOT}\" == \"\" ]] ; then \\\n",
    "    echo \"Please set GONB_GIT_ROOT before runnig this notebook!\" 1>&2 ; \\\n",
    "else \\\n",
    "    echo \"ok\" ; \\\n",
    "fi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6d0b2859-40e9-4c71-bf1a-1f68485e7a27",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t- Added replace rule for module \"github.com/janpfeifer/gonb\" to local directory \"/home/janpf/Projects/gonb\".\n"
     ]
    }
   ],
   "source": [
    "!*rm -f go.work && go work init && go work use . \"${GONB_GIT_ROOT}\"\n",
    "%goworkfix"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be8ad48f-5ded-4db8-b72d-c6dd5380535c",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "### Here the testing really starts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a1f2fb17-6c15-4ea7-9a14-e949fda9e618",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "  foo\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "str=foo\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "  ········\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pass=bar\n"
     ]
    }
   ],
   "source": [
    "%with_inputs\n",
    "!read str ; echo \"str=$str\"\n",
    "%with_password\n",
    "!read pass ; echo \"pass=$pass\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e06944dc-e366-4ac7-a566-1587c9bba66c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Enter: 42\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "int=42\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Pin: ········\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "secret=123456\n"
     ]
    }
   ],
   "source": [
    "import (\n",
    "    \"fmt\"\n",
    "    \"github.com/janpfeifer/gonb/gonbui\"\n",
    ")\n",
    "%%\n",
    "gonbui.RequestInput(\"Enter:\", false)\n",
    "var x int\n",
    "fmt.Scan(&x)\n",
    "fmt.Printf(\"int=%d\\n\", x)\n",
    "\n",
    "gonbui.RequestInput(\"Pin:\", true)\n",
    "fmt.Scan(&x)\n",
    "fmt.Printf(\"secret=%d\\n\", x)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Go (gonb)",
   "language": "go",
   "name": "gonb"
  },
  "language_info": {
   "codemirror_mode": "",
   "file_extension": ".go",
   "mimetype": "text/x-go",
   "name": "go",
   "nbconvert_exporter": "",
   "pygments_lexer": "",
   "version": "go1.25.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
